﻿using StartsEAS_API.DAL.DALTools;
using StartsEAS_API.Model;
using StartsEAS_API.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StartsEAS_API.DAL.AlterWorkerD
{
    public class AlterWorkerDAL
    {
        private readonly StarsEASContext _context;
        public AlterWorkerDAL(StarsEASContext context) {
            _context = context;
        }

        public ResultUtils GetAllAlterWorker() {
            return new ResultUtils() { code = 200, message = _context.AlterWorkers.ToList() };
        }

        public ResultUtils GetAllAlterWorkerByWorkerId(string token) {
            Worker worker = token.GetWorkerByToken(_context);
            List<AlterWorker> alterWorkerList = _context.AlterWorkers
                .OrderByDescending(a=>a.AlterToApplyForTime)
                .Where(a=>a.WorkerId.Equals(worker.WorkerId)).ToList();
            return new ResultUtils() { code = 200, message = alterWorkerList };
        }
    }
}
